package asteroids.expression;

import asteroids.model.programs.Program;

public   class Variable extends Expression{

	protected String name;
	protected Expression exp;
	
	public Variable(String name) {
	
			this.name = name;
	
	}
	
	
	
	
	@Override
	public String toString(Program program) {
		return "" + this.getValue(program);
	}

	public Object getValue(Program program){
		if(program.getGlobals().get(name) instanceof NumericExpression){
		return ((Object)(((NumericExpression)program.getGlobals().get(name)).getValue(program)));
		}else if(program.getGlobals().get(name) instanceof BooleanExpression){
		return ((Object)(((BooleanExpression)program.getGlobals().get(name)).getValue(program)));	
		}else if(program.getGlobals().get(name) instanceof EntityExpression){
			return ((Object)(((EntityExpression)program.getGlobals().get(name)).getValue(program)));	
			}else{
		return null;
			
		}
	}
	
	public Expression getRef(Program program){
		if(program.getGlobals().get(name) instanceof Variable){
			return ((Variable)program.getGlobals().get(name)).getRef(program);
		}else{
		return program.getGlobals().get(name);}
	}
	
	public void updateArguments(Program program) {}
}
